package com.ruoyi.prodata.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.workorder.service.IWorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author renyuxin
 */
@RestController
@RequestMapping("/prodata/problemStatistics")
public class ProblemStatisticsController extends BaseController {

    @Autowired
    private IWorkOrderService workOrderService;

    @PreAuthorize("@ss.hasPermi('prodata:statistics:list')")
    @GetMapping("/list")
    public AjaxResult list(Long projectId){
        //查询每个项目的工单数量和活动名称 饼状图数据
        List<Map<String,Object>> list = workOrderService.listProblemStatistics(projectId);

        List<Object> result = new ArrayList<>();
        for (Map<String, Object> item : list) {
            result.add(new HashMap<String, Object>() {{
                put("name", Convert.toStr(item.get("name")));
                put("count", Convert.toLong(item.get("count")));
            }});
        }
        return success(result);
    }

}
